﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Spring.Context;
using Spring.Context.Support;
using XTeam.Document.Factory.DataAccessInterface;
using XTeam.Document.Entities.Words;

namespace XTeam.Documents.Business
{
    public class WordsBLL : BasicBLL
    {
        private IWordsDataAccess _wordsDal;
        public WordsBLL()
        {
            IApplicationContext _context = ContextRegistry.GetContext();
            _wordsDal = (IWordsDataAccess)_context.GetObject("WordsDataAccess");
        }

        public WordsEntity FindWord(string word)
        {
            return _wordsDal.Find<WordsEntity>(i => i.Word.ToUpper() == word.ToUpper());
        }

        public int UpdateWord(WordsEntity word)
        {
            return _wordsDal.Update<WordsEntity>(new WordsEntity[] { word });
        }

        public int AppendWord(WordsEntity word)
        {
            return _wordsDal.Append<WordsEntity>(new WordsEntity[] { word });
        }

        public IList<WordsEntity> Search(Func<WordsEntity, bool> filter, int pageIndex, int pageSize, out int totalRows)
        {
            return _wordsDal.Search(filter, pageIndex, pageSize, out totalRows).ToList();
        }

        public int DelWords(string[] words)
        {
            List<WordsEntity> list = new List<WordsEntity>();
            foreach (var word in words)
            {
                list.Add(new WordsEntity()
                {
                    Word = word
                });
            }
            return _wordsDal.Delete(list);
        }
    }
}
